home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / mxcode / sbprocss / sinemix.c < prev    next >
C/C++ Source or Header  |  1995-01-14  |  981b  |  56 lines

  1. /* sinemix.c */
  2.  
  3. #include <conio.h>
  4. #include "sbsample.c"
  5. #include <math.h>
  6.  
  7. #define WAVELENGTH 50
  8. #define AMPLITUDE  64
  9.  
  10. signed char sines[WAVELENGTH];
  11. unsigned int x;
  12.  
  13. void initsines(void)
  14.   {
  15.     char i;
  16.     for (i = 0; i < WAVELENGTH; i++)
  17.       sines[i] = sin((2*M_PI)*((float)i/WAVELENGTH))*AMPLITUDE;
  18.   }
  19.  
  20. void clipsample(signed int *sample)
  21.   {
  22.     if (*sample > 127)  *sample = 127;
  23.     if (*sample < -128) *sample = -128;
  24.   }
  25.  
  26. void processsample(signed char *sample)
  27.   {
  28.     signed int temp;
  29.  
  30.     temp = *sample - 128;
  31.  
  32.     /* Process sample here */
  33.     temp = temp + sines[x];
  34.  
  35.     clipsample(&temp);
  36.     *sample = temp + 128;
  37.   }
  38.  
  39. int main(void)
  40.   {
  41.     unsigned char sample;
  42.  
  43.     initsines();
  44.     resetdsp();
  45.     x = 0;
  46.     while (!kbhit())
  47.       {
  48.         sample = getsample();
  49.         processsample(&sample);
  50.         outputsample(sample);
  51.         x = (++x % WAVELENGTH);
  52.       }
  53.     getch();
  54.  
  55.     return(0);
  56.   }